package cn.ahaoweb.drule.core;

import cn.ahaoweb.drule.core.callback.AfterCreateSessionCallback;
import cn.ahaoweb.drule.core.configuration.Configuration;
import cn.ahaoweb.drule.core.configuration.Option;
import cn.ahaoweb.drule.core.constant.RuleType;

import java.util.ArrayList;

/**
 * @Name: DruleServiceHelper
 * @Description:
 * @Author: wangzhonghao
 * @Date: 2025/2/13 16:47
 */
public class DruleServiceHelper {

    public RuleServiceImpl ruleService;

    public DruleServiceHelper() {
        this(new RuleServiceImpl());
    }

    public DruleServiceHelper(RuleService ruleService) {
        this.ruleService = (RuleServiceImpl) ruleService;
    }

    public DruleServiceHelper identifier(String identifier){
        ruleService.identifier = identifier;
        return this;
    }

    public DruleServiceHelper version(String version){
        ruleService.version = version;
        return this;
    }

    public DruleServiceHelper pkg(String pkg){
        ruleService.version = pkg;
        return this;
    }

    public DruleServiceHelper config(Configuration config){
        ruleService.config = config;
        return this;
    }

    public DruleServiceHelper addContent(RuleType type, String content) {
        if (ruleService.fileContents.get(type) == null) {
            ruleService.fileContents.put(type, new ArrayList<>());
        }
        ruleService.fileContents.get(type).add(content);
        return this;
    }

    public DruleServiceHelper addConfig(Option option) {
        ruleService.addConfig(option);
        return this;
    }

    public DruleServiceHelper factClassSelector(FactClassSelector selector){
        ruleService.factClassSelector(selector);
        return this;
    }

    public DruleServiceHelper afterCreateSessionCallback(AfterCreateSessionCallback callback){
        ruleService.afterCreateSessionCallback(callback);
        return this;
    }

    public RuleService getRuleService() {
        return ruleService.init();
    }
}
